package com.lzx.adx.report.controller.v1.cps.meituan;


import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.lzs.adx.commmon.utils.JsonUtils;
import com.lzs.adx.commmon.utils.Result;
import com.lzx.adx.report.bean.mapper.ReportMapper;
import com.lzx.adx.report.cache.AccountLocalCache;
import com.lzx.adx.report.dto.AccountDTO;
import com.lzx.adx.report.dto.ReportDTO;
import com.lzx.adx.report.model.huawei.request.HwReportRequest;
import com.lzx.adx.report.service.ReportService;
import com.lzx.adx.report.util.UrlUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * 广告上报
 */
@RequestMapping("/hw/mt")
@RestController
@Slf4j
public class HwMeituanController {


    @Autowired
    private ReportService reportService;



    @Autowired
    private ThreadPoolTaskExecutor reportExecutor;

    @Autowired
    private ReportMapper reportMapper;







    @GetMapping("/report")
    public ResponseEntity hwReqport(HwReportRequest hwReportRequest, HttpServletRequest request){
        log.info("接收到的请求参数为{}", JsonUtils.toJsonString(hwReportRequest));
        //1.收到监测的数据存储
        ReportDTO reportDTO=reportMapper.toReportDTO(hwReportRequest);
        reportDTO.setEventType(hwReportRequest.getType());
        reportDTO.setBizRequestId(IdUtil.fastUUID());
        reportDTO.setCreateTime(new Date());
        reportDTO.setUpdateTime(new Date());

        reportExecutor.execute(()->{
            reportService.saveData(reportDTO);
        });


        return ResponseEntity.ok(new Result());
    }
}
